/**
 * 
 */
package com.geezdata.cps.ttk_admin.api.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.geezdata.cps.base.annotation.LoggerOut;
import com.geezdata.cps.base.response.BaseResponse;
import com.geezdata.cps.cqrs.command.Command;
import com.geezdata.cps.cqrs.command.bus.CommandBus;
import com.geezdata.cps.ttk.common.request.CreateJobRequest;
import com.geezdata.cps.ttk.common.request.QueryJobListRequest;
import com.geezdata.cps.ttk.common.response.CreateJobResult;
import com.geezdata.cps.ttk.common.response.QueryJobListResult;
import com.geezdata.cps.ttk.query.query.JobService;

/**
 * @author sszheng
 * @date 创建时间：2017年9月14日 下午3:27:11
 *
 */
@RestController
@RequestMapping(value="/job")
public class JobController {
	@Autowired
    private CommandBus commandBus;
	
	@Autowired
	private Command<CreateJobRequest, CreateJobResult> createJobCommand;
	
	@Autowired
	private JobService jobService;
	
	@LoggerOut
    @RequestMapping(value = "/create", method = RequestMethod.POST)
    public BaseResponse<CreateJobResult> create(@RequestBody CreateJobRequest request) {
		return commandBus.dispatch(createJobCommand, request);
    }
	
	@LoggerOut
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    public BaseResponse<QueryJobListResult> getJobList(@RequestBody QueryJobListRequest request) {
		return BaseResponse.success(jobService.getJobList(request));
    }
	
}
